package com.zh.note.leetcode;

/**
 * 1013. 将数组分成和相等的三个部分
 */
public class LC_1013_canThreePartsEqualSum {

    public static boolean canThreePartsEqualSum(int[] arr) {
        int sum = 0;
        for (int item : arr) {
            sum += item;
        }
        if (sum % 3 != 0) {
            return false;
        }
        sum = sum / 3;
        int count = 0;
        int curSum = 0;
        for (int i = 0; i < arr.length; i++) {
            curSum += arr[i];
            if (curSum == sum) {
                count++;
                curSum = 0;
            }
        }
        return count == 3 || (count > 3 && sum == 0);


    }

    public static void main(String[] args) {
        int[] nums = {0, 2, 1, -6, 6, -7, 9, 1, 2, 0, 1};
        canThreePartsEqualSum(nums);
    }
}
